#ifndef DB_H
#define DB_H

#include <sqlite3.h>

// 数据库初始化与清理
int init_database(sqlite3 **db);
void close_database(sqlite3 *db);

// 用户管理操作
// int add_user(sqlite3 *db, const char *username, const char *password, int permission_level);
int add_user(sqlite3 *db,
             const char *username,
             const unsigned char *password_hash, // Pre-computed hash
             const unsigned char *salt,          // Salt used for the hash
             int salt_len,
             int hash_len,
             int permission_level);
int authenticate_user(sqlite3 *db, const char *username, const char *password);
int get_user_id(sqlite3 *db, const char *username);
int get_user_permission_level(sqlite3 *db, int user_id);

// 新增 user_register 函数声明
int user_register(sqlite3 *db, const char *username, const char *password);

// 文件权限操作
// int add_file_permission(sqlite3 *db, int user_id, const char *file_path, int can_read, int can_write);
int add_file_permission(sqlite3 *db, int user_id, const char *file_path, int can_read, int can_write, int can_delete);
int check_file_permission(sqlite3 *db, int user_id, const char *file_path, int operation_type);
int list_user_accessible_files(sqlite3 *db, int user_id, char ***file_list, int *count);

// 审计日志操作
int add_audit_log(sqlite3 *db, int user_id, const char *operation, const char *file_path, int status_code);
int list_audit_logs(sqlite3 *db, char ***log_list, int *count, const char *filter);

// 操作类型常量
#define OPERATION_READ 1
#define OPERATION_WRITE 2
#define OPERATION_DELETE 3

#endif /* DB_H */